package com.shunya.diskorganizer.tinytypes;

public abstract class StringValueType extends AbstractValueType<String> {

    protected StringValueType(String value) {
        super(value.trim());
        assertNotEmpty(value);
    }

    @Override
    public int compareTo(AbstractValueType<?> other) {
        if(other instanceof StringValueType) {
            StringValueType otherStringValueType = (StringValueType) other;
            return value().compareTo(otherStringValueType.value());
        }
        return super.compareTo(other);
    }

    private void assertNotEmpty(String value) {
        if (value.isEmpty())
            throw new IllegalArgumentException(String.format("%s value cannot be empty", this.getClass().getSimpleName()));

    }
}